﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using WP7PhoneTracker.EntityClasses;

namespace WP7PhoneTracker.Helpers
{
    public class CrudTrackingName
    {
        internal static Boolean AddTrackingName(TrackingName TrackingName)
        {
            try
            {
                using (var context = new TrackerDataContext(App.ConnectionString))
                {
                    //Add a new TrackingName to the context
                    context.TrackingNames.InsertOnSubmit(TrackingName);
                    context.SubmitChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }

        internal static IList<TrackingName> GetTrackingNames()
        {
            try
            {
                IList<TrackingName> trackingNames = null;
                using (var context = new TrackerDataContext(App.ConnectionString))
                    trackingNames = (from c in context.TrackingNames select c).ToList();
                return trackingNames;
            }
            catch
            {
                return null;
            }
        }

        internal static Boolean DeleteTrackingName(TrackingName TrackingName)
        {
            try
            {
                using (var context = new TrackerDataContext(App.ConnectionString))
                {
                    TrackingName res = (from dt in context.TrackingNames where dt.Id == TrackingName.Id select dt).Single();

                    context.TrackingNames.DeleteOnSubmit(res);
                    context.SubmitChanges();
                }
                return true;
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
                return false;
            }
        }
    }
}
